/*
 * key.h
 *
 * Created: 8/19/2013 2:49:46 PM
 *  Author: Ken Arok
 *
 * \brief Middleware Driver of Keypad User Interface.
 *
 * Copyright (c) 2013 PT Hanindo Automation Solutions. All rights reserved.
 *
 */

/** \section section_keypad_driver Keypad Driver
 * \brief This module describes how to user API library of the keypad.
*/


#ifndef KEY_H_
#define KEY_H_

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "semphr.h"

/** \name Keyword definition
 */
//! @{
/* MSB [SC4 SC3 SC2 SC1 * 7 4 1 0 8 5 2 # 9 6 3] LSB
   0 -> pressed
   1 -> released */
#define KEYWORD_SHORTCUT4		0x7FFF
#define KEYWORD_SHORTCUT3		0xBFFF
#define KEYWORD_SHORTCUT2		0xDFFF
#define KEYWORD_SHORTCUT1		0xEFFF
#define KEYWORD_ASTERIC			0xF7FF
#define KEYWORD_NUMBER7			0xFBFF
#define KEYWORD_NUMBER4			0xFDFF
#define KEYWORD_NUMBER1			0xFEFF
#define KEYWORD_NUMBER0			0xFF7F
#define KEYWORD_NUMBER8			0xFFBF
#define KEYWORD_NUMBER5			0xFFDF
#define KEYWORD_NUMBER2			0xFFEF
#define KEYWORD_CROSS			0xFFF7
#define KEYWORD_NUMBER9			0xFFFB
#define KEYWORD_NUMBER6			0xFFFD
#define KEYWORD_NUMBER3			0xFFFE
#define KEYWORD_NONE			0xFFFF
//! @}

/**\name Key Combine Definition.
 *
 */
//! @{
/* MSB [SC4 SC3 SC2 SC1 * 7 4 1 0 8 5 2 # 9 6 3] LSB */
#define KEYWORD_COMBINE1		0xF111		//!< * and 5 and 9
#define KEYWORD_COMBINE2		0xF444		//!< 7 and 0 and 3
#define KEYWORD_COMBINE3		0xFAAA		//!< 7 and 2 and 3
#define KEYWORD_COMBINE4		0xF1F1		//!< * and 7 and 6
#define KEYWORD_COMBINE5		0xF4F4		//!< * and 4 and 3
#define KEYWORD_COMBINE11		0xFEFE		//!< 1 and 3
#define KEYWORD_COMBINE12		0xFFAA		//!< 2 and 9
#define KEYWORD_COMBINE13		0xFF99		//!< 6 and 8
#define KEYWORD_COMBINE14		0xFAAF		//!< 1 and 8
#define KEYWORD_COMBINE15		0xF9F9		//!< 6 and 7
//! @}

extern xSemaphoreHandle xKeySignaling;

/*! \defgroup KEY_DRIVERS The Driver of Keypad
 * \{
 */

/** \brief Enable keypad interface.
 * <pre><key.h></pre>
 * <pre>\b void \b vEnableKey(void);</pre>
 */
extern void vEnableKey(void);

/** \brief Disable keypad interface.
 * <pre><key.h></pre>
 * <pre>\b void \b vDisableKey(void);</pre>
 */
extern void vDisableKey(void);

/** \brief Initialize keypad interface.
 * <pre><key.h></pre>
 * <pre>\b void \b vInitKey(void);</pre>
 */
extern void vInitKey(void);

/** \brief Get 16 bit representation of pressed key.
 * <pre><key.h></pre>
 * <pre>\b uint16_t \b vGetKeyWord(void);</pre>
 *
 * @return KEYWORD		16 bit key representative of pressed button.
 */
extern uint16_t vGetKeyWord(void);

/** \brief Get character representation of pressed key.
 * <pre><key.h></pre>
 * <pre>\b char \b vGetKeyChar(void);</pre>
 *
 * @return KEYCHAR		Character of key pressed representation.
 */
extern char vGetKeyChar(void);

/** \brief Get 16 bit representation of pressed combination key.
 * <pre><key.h></pre>
 * <pre>\b uint16_t \b vGetKeyCombine(void);</pre>
 *
 * @return KEYCOMBINE	16 bit key representative of pressed button.
 */
extern uint16_t vGetKeyCombine(void);

/** \brief Wait until one of wanted characters of keypad is pressed.
 * <pre><key.h></pre>
 * <pre>\b char \b vWaitKeyChar(const char *_stringWaitKey);</pre>
 *
 * @param	_stringWaitKey		Pointer to the string of waited characters.
 *
 * @return Status
 *	@retval 0			Failed
 *	@retval Keychar		Character of pressed key.
 */
extern char vWaitKeyChar(const char *_stringWaitKey);

/** \brief Wait until keypad is released.
 * <pre><key.h></pre>
 * <pre>\b void \b vWaitKeyRelease(void);</pre>
 */
extern void vWaitKeyRelease(void);

/**
 * \}
 */

#endif /* KEY_H_ */
